package com.fjnldx.ks.utils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fjnldx.ks.mapper.MesForthMapper;
import com.fjnldx.ks.mapper.shiftManagement.SchedulingShiftMapper;
import com.fjnldx.ks.mapper.shiftManagement.SchedulingShiftSystemMapper;
import com.fjnldx.ks.pojo.domain.ProcessSheet;
import com.fjnldx.ks.pojo.domain.SchedulingShift;
import com.fjnldx.ks.pojo.mesDoMain.MesScjhCusha;
import com.fjnldx.ks.pojo.mesDoMain.MesScjhLuotong;
import com.fjnldx.ks.pojo.mesDoMain.MesScjhXisha;
import com.fjnldx.ks.pojo.request.SchedulingShiftInModel;
import com.fjnldx.ks.pojo.response.Result;
import com.fjnldx.ks.pojo.response.Result2;
import jxl.Sheet;
import jxl.Workbook;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.File;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Component
public class Common {
    @Autowired
    MesForthMapper mesForthMapper;
    @Resource
    SchedulingShiftMapper schedulingShiftMapper;
    @Resource
    SchedulingShiftSystemMapper schedulingShiftSystemMapper;

    /**
     * 根据轮班管理查询当前班次
     *
     * @param params
     * @return
     */
    public List<SchedulingShift> querySchedulingShift(SchedulingShiftInModel params) {
        String org = params.getOrg();
        String cj = params.getCj();
        String gx = params.getGongxu();
        LocalDate time = params.getTime();
        LocalDateTime now = LocalDateTime.now();
        QueryWrapper<SchedulingShift> wrapper = new QueryWrapper<>();
        wrapper.eq("org", org);
        wrapper.eq("cj", cj);
        wrapper.eq("gongxu", gx);
        wrapper.apply(String.format("DATEDIFF(startTime,'%s')=0", time));
        wrapper.apply(String.format("startTime < '%s'", now));
        wrapper.apply(String.format("endTime >= '%s'", now));
        return schedulingShiftMapper.selectList(wrapper);
    }

    /**
     * 获取excel所有数据
     *
     * @param file 文件路径
     */
    public List<ProcessSheet> getAllByExcel(String file) {
        ArrayList<ProcessSheet> list = new ArrayList<>();
        try {
            //System.out.println(file);
            Workbook rwb = Workbook.getWorkbook(new File(file));
            Sheet rs = rwb.getSheet(0);// 或者rwb.getSheet(0)rwb.getSheet("用户信息");
            int clos = rs.getColumns();// 得到所有的列
            int rows = rs.getRows();// 得到所有的行
            //System.out.println(clos + " rows:" + rows);
            for (int i = 1; i < rows; i++) {
                for (int j = 0; j < clos; j++) {
                    // 第一个是列数，第二个是行数
                    String specnum = rs.getCell(j++, i).getContents();// 默认最左边编号也算一列
                    if (specnum == null || "".equals(specnum)) {
                        specnum = "0";
                    }
                    // 所以这里得j++
                    String version = rs.getCell(j++, i).getContents();
                    String org = rs.getCell(j++, i).getContents();
                    String workshop = rs.getCell(j++, i).getContents();
                    String equipment = rs.getCell(j++, i).getContents();
                    String vart_code = rs.getCell(j++, i).getContents();
                    String cur_vart = rs.getCell(j++, i).getContents();
                    String ori_vart = rs.getCell(j++, i).getContents();
                    String machine = rs.getCell(j++, i).getContents();
                    String name = rs.getCell(j++, i).getContents();
                    String gongxu = rs.getCell(j++, i).getContents();
                    String status = rs.getCell(j++, i).getContents();
                    list.add(new ProcessSheet(specnum, version, org, workshop, equipment, vart_code, cur_vart, ori_vart, machine, name, gongxu, status));
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    /**
     * 获取excel所有数据---细纱
     *
     * @param filePath 文件路径
     */
    public List<MesScjhXisha> getAllByExcelScjhXiSha(String filePath) {
        ArrayList<MesScjhXisha> list = new ArrayList<>();
        try {
            //System.out.println(file);
            Workbook rwb = Workbook.getWorkbook(new File(filePath));
            Sheet rs = rwb.getSheet(0);// 或者rwb.getSheet(0)rwb.getSheet("用户信息");
            int clos = rs.getColumns();// 得到所有的列
            int rows = rs.getRows();// 得到所有的行
            //System.out.println(clos + " rows:" + rows);
            for (int i = 1; i < rows; i++) {
                for (int j = 0; j < clos; j++) {
                    // 第一个是列数，第二个是行数
                    String scjhbh = rs.getCell(j++, i).getContents();// 默认最左边编号也算一列
                    //if (scjhbh == null || "".equals(scjhbh)) scjhbh = "0";
                    // 所以这里得j++
                    String cj = rs.getCell(j++, i).getContents();
                    String btjth = rs.getCell(j++, i).getContents();
                    String btts = rs.getCell(j++, i).getContents();
                    String bttc = rs.getCell(j++, i).getContents();
                    String csjth = rs.getCell(j++, i).getContents();
                    String csts = rs.getCell(j++, i).getContents();
                    String xsjth = rs.getCell(j++, i).getContents();
                    String xsts = rs.getCell(j++, i).getContents();
                    String xstct = rs.getCell(j++, i).getContents();
                    String xsclt = rs.getCell(j++, i).getContents();
                    String xspz = rs.getCell(j++, i).getContents();
                    String ds = rs.getCell(j++, i).getContents();
                    String dl = rs.getCell(j++, i).getContents();
                    String cs = rs.getCell(j++, i).getContents();
                    String xiaolv = rs.getCell(j++, i).getContents();
                    String de = rs.getCell(j++, i).getContents();
                    String sygs = rs.getCell(j++, i).getContents();
                    String sygsts = rs.getCell(j++, i).getContents();
                    String zgsts = rs.getCell(j++, i).getContents();
                    String sTime = rs.getCell(j++, i).getContents();
                    Date time = this.changeExcelTime(sTime);
                    MesScjhXisha mesScjhXisha = new MesScjhXisha();
                    mesScjhXisha.setScjhbh(scjhbh);
                    mesScjhXisha.setCj(cj);
                    mesScjhXisha.setBtjth(btjth);
                    mesScjhXisha.setBtts(btts);
                    mesScjhXisha.setBttc(bttc);
                    mesScjhXisha.setCsjth(csjth);
                    mesScjhXisha.setCsts(csts);
                    mesScjhXisha.setXsjth(xsjth);
                    mesScjhXisha.setXsts(xsts);
                    mesScjhXisha.setXstct(xstct);
                    mesScjhXisha.setXsclt(xsclt);
                    mesScjhXisha.setXspz(xspz);
                    mesScjhXisha.setDs(ds);
                    mesScjhXisha.setDl(dl);
                    mesScjhXisha.setCs(cs);
                    mesScjhXisha.setXiaolv(xiaolv);
                    mesScjhXisha.setDe(de);
                    mesScjhXisha.setSygs(sygs);
                    mesScjhXisha.setSygsts(sygsts);
                    mesScjhXisha.setZgsts(zgsts);
                    mesScjhXisha.setTime(time);
                    list.add(mesScjhXisha);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    /**
     * 是否存在该生产计划---细纱
     *
     * @param scjhbh
     * @return
     */
    public boolean isExistScjhXiSha(String scjhbh) {
        MesScjhXisha scbhXisha = mesForthMapper.findScbhXisha(scjhbh);
        return scbhXisha != null;
    }

    /**
     * 获取excel所有数据---粗纱
     *
     * @param filePath 文件路径
     */
    public List<MesScjhCusha> getAllByExcelScjhCuha(String filePath) {
        ArrayList<MesScjhCusha> list = new ArrayList<>();
        try {
            Workbook rwb = Workbook.getWorkbook(new File(filePath));
            Sheet rs = rwb.getSheet(0);// 或者rwb.getSheet(0)rwb.getSheet("用户信息");
            int clos = rs.getColumns();// 得到所有的列
            int rows = rs.getRows();// 得到所有的行
            //System.out.println(clos + " rows:" + rows);
            for (int i = 1; i < rows; i++) {
                for (int j = 0; j < clos; j++) {
                    // 第一个是列数，第二个是行数
                    String scjhbh = rs.getCell(j++, i).getContents();// 默认最左边编号也算一列
                    // 所以这里得j++
                    String cj = rs.getCell(j++, i).getContents();
                    String gongxu = rs.getCell(j++, i).getContents();
                    String qfpz = rs.getCell(j++, i).getContents();
                    String xh = rs.getCell(j++, i).getContents();
                    String cjtz = rs.getCell(j++, i).getContents();
                    String jhts = rs.getCell(j++, i).getContents();
                    String jakt = rs.getCell(j++, i).getContents();
                    String ybkt = rs.getCell(j++, i).getContents();
                    String bckt = rs.getCell(j++, i).getContents();
                    String qk = rs.getCell(j++, i).getContents();
                    String ds = rs.getCell(j++, i).getContents();
                    String dl = rs.getCell(j++, i).getContents();
                    String cs = rs.getCell(j++, i).getContents();
                    String xiaolv = rs.getCell(j++, i).getContents();
                    String de = rs.getCell(j++, i).getContents();
                    String xsjhcl = rs.getCell(j++, i).getContents();
                    String jat = rs.getCell(j++, i).getContents();
                    String ybt = rs.getCell(j++, i).getContents();
                    String sTime = rs.getCell(j++, i).getContents();
                    Date time = this.changeExcelTime(sTime);
                    MesScjhCusha mesScjhCusha = new MesScjhCusha();
                    mesScjhCusha.setScjhbh(scjhbh);
                    mesScjhCusha.setCj(cj);
                    mesScjhCusha.setGongxu(gongxu);
                    mesScjhCusha.setQfpz(qfpz);
                    mesScjhCusha.setXh(xh);
                    mesScjhCusha.setCjtz(cjtz);
                    mesScjhCusha.setJhts(jhts);
                    mesScjhCusha.setJakt(jakt);
                    mesScjhCusha.setYbkt(ybkt);
                    mesScjhCusha.setBckt(bckt);
                    mesScjhCusha.setQk(qk);
                    mesScjhCusha.setDs(ds);
                    mesScjhCusha.setDl(dl);
                    mesScjhCusha.setCs(cs);
                    mesScjhCusha.setXiaolv(xiaolv);
                    mesScjhCusha.setDe(de);
                    mesScjhCusha.setXsjhcl(xsjhcl);
                    mesScjhCusha.setJat(jat);
                    mesScjhCusha.setYbt(ybt);
                    mesScjhCusha.setTime(time);
                    list.add(mesScjhCusha);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    /**
     * 获取excel所有数据---络筒
     *
     * @param filePath 文件路径
     */
    public List<MesScjhLuotong> getAllByExcelScjhLuoTong(String filePath) {
        ArrayList<MesScjhLuotong> list = new ArrayList<>();
        try {
            Workbook rwb = Workbook.getWorkbook(new File(filePath));
            Sheet rs = rwb.getSheet(0);// 或者rwb.getSheet(0)rwb.getSheet("用户信息");
            int clos = rs.getColumns();// 得到所有的列
            int rows = rs.getRows();// 得到所有的行
            //System.out.println(clos + " rows:" + rows);
            for (int i = 1; i < rows; i++) {
                for (int j = 0; j < clos; j++) {
                    MesScjhLuotong mesScjhLuotong = new MesScjhLuotong();
                    // 第一个是列数，第二个是行数
                    String scjhbh = rs.getCell(j++, i).getContents();// 默认最左边编号也算一列
                    //if (scjhbh == null || "".equals(scjhbh)) scjhbh = "0";
                    // 所以这里得j++
                    String cj = rs.getCell(j++, i).getContents();
                    String chph = rs.getCell(j++, i).getContents();
                    String lzpz = rs.getCell(j++, i).getContents();
                    String jth = rs.getCell(j++, i).getContents();
                    String jakt = rs.getCell(j++, i).getContents();
                    String jbkt = rs.getCell(j++, i).getContents();
                    String jckt = rs.getCell(j++, i).getContents();
                    String jhts = rs.getCell(j++, i).getContents();
                    String ds = rs.getCell(j++, i).getContents();
                    String dl = rs.getCell(j++, i).getContents();
                    String cs = rs.getCell(j++, i).getContents();
                    String xiaolv = rs.getCell(j++, i).getContents();
                    String de = rs.getCell(j++, i).getContents();
                    String llcl = rs.getCell(j++, i).getContents();
                    String xsjhcl = rs.getCell(j++, i).getContents();
                    String lsjhcl = rs.getCell(j++, i).getContents();
                    String jhcllt = rs.getCell(j++, i).getContents();
                    String jat = rs.getCell(j++, i).getContents();
                    String ybt = rs.getCell(j++, i).getContents();
                    String bct = rs.getCell(j++, i).getContents();
                    mesScjhLuotong.setScjhbh(scjhbh);
                    mesScjhLuotong.setCj(cj);
                    mesScjhLuotong.setChph(chph);
                    mesScjhLuotong.setLzpz(lzpz);
                    mesScjhLuotong.setJth(jth);
                    mesScjhLuotong.setJakt(jakt);
                    mesScjhLuotong.setJbkt(jbkt);
                    mesScjhLuotong.setJckt(jckt);
                    mesScjhLuotong.setJhts(jhts);
                    mesScjhLuotong.setDs(ds);
                    mesScjhLuotong.setDl(dl);
                    mesScjhLuotong.setCs(cs);
                    mesScjhLuotong.setXiaolv(xiaolv);
                    mesScjhLuotong.setDe(de);
                    mesScjhLuotong.setLlcl(llcl);
                    mesScjhLuotong.setXsjhcl(xsjhcl);
                    mesScjhLuotong.setLsjhcl(lsjhcl);
                    mesScjhLuotong.setJhcllt(jhcllt);
                    mesScjhLuotong.setJat(jat);
                    mesScjhLuotong.setYbt(ybt);
                    mesScjhLuotong.setBct(bct);
                    String sTime = rs.getCell(j++, i).getContents();
                    Date date = this.changeExcelTime(sTime);
                    mesScjhLuotong.setTime(date);
                    list.add(mesScjhLuotong);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return list;
    }

    /**
     * 是否存在该生产计划---细纱
     *
     * @param scjhbh
     * @return
     */
    public boolean isExistScjhCuSha(String scjhbh) {
        MesScjhCusha scjhCuSha = mesForthMapper.findScjhCuSha(scjhbh);
        return scjhCuSha != null;
    }

    /**
     * 是否存在该生产计划---络筒
     *
     * @param scjhbh
     * @return
     */
    public boolean isExistScjhLuoTong(String scjhbh) {
        System.out.println(mesForthMapper.findScjhLuoTong(scjhbh));
        MesScjhLuotong scjhLuoTong = mesForthMapper.findScjhLuoTong(scjhbh);
        return scjhLuoTong != null;
    }

    /**
     * 上传文件-生成文件路径
     *
     * @param file
     * @return
     */
    public Result uploadExcelFile(MultipartFile file) {
        Result result = new Result();
        if (file.isEmpty()) {
            return Result.error("文件上传失败，请选择文件");
        }
        String fileName = file.getOriginalFilename();
        String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1);
        // && !fileExt.equals("xlsx")
        if (!fileExt.equals("xls")) {
            return Result.error("文件格式错误，上传失败");
        }
        // 文件格式正确，继续执行
        String userDir = System.getProperty("user.dir");
        String filePath = userDir + "/src/main/resources/WEB-INF/files/";
        result.setMsg(filePath + fileName);
        return result;
    }

    /**
     * 判断数据库中是否存在工艺单编号
     *
     * @param specnum
     * @return
     */
    public boolean isExist(String specnum) {
        ProcessSheet specNum = mesForthMapper.findSpecNum(specnum);
        return specNum != null;
    }

    public Result2 getResult(Object object, Integer total) {
        Result2 result2 = new Result2();
        if (object != null) {
            result2.setCode(1);
            result2.setStatus("success");
            result2.setMsg("查询成功");
            result2.setData(object);
            result2.setTotal(total);
        } else {
            result2.setCode(-1);
            result2.setStatus("error");
            result2.setMsg("查询失败");
        }
        return result2;
    }

    /**
     * excel时间格式转换
     *
     * @param excelTime
     * @return
     */
    public Date changeExcelTime(String excelTime) {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String sTime = excelTime.substring(1);
        Date time;
        try {
            time = formatter.parse(sTime);
        } catch (Exception e) {
            System.out.println("time走了null");
            time = null;
        }
        return time;
    }

    /**
     * 汇总数据公共方法--求和
     */
    //public SumLuoTong huiZongLuoTongSum(String json, String base) throws Exception {
    //    JSONObject jsonObject = new JSONObject(json);
    //    int sum1 = 0;
    //    int sum2 = 0;
    //    int sum3 = 0;
    //    int sum4 = 0;
    //    for (int i = 1; i <= jsonObject.length(); i++) {
    //        String fBase = base + i;
    //        if (i <= 16) {
    //            sum1 += Integer.parseInt(jsonObject.get(fBase).toString());
    //        } else if (i <= 32) {
    //            sum2 += Integer.parseInt(jsonObject.get(fBase).toString());
    //        } else if (i <= 48) {
    //            sum3 += Integer.parseInt(jsonObject.get(fBase).toString());
    //        } else if (i <= 64) {
    //            sum4 += Integer.parseInt(jsonObject.get(fBase).toString());
    //        }
    //    }
    //    SumLuoTong sumLuoTong = new SumLuoTong();
    //    sumLuoTong.setSum1(sum1);
    //    sumLuoTong.setSum2(sum2);
    //    sumLuoTong.setSum3(sum3);
    //    sumLuoTong.setSum4(sum4);
    //    return sumLuoTong;
    //}

    /**
     * 汇总数据公共方法--求和-单个
     */
    public int huiZongLuoTongSumSingle(String json, String base) throws Exception {
        JSONObject jsonObject = new JSONObject(json);
        int sum = 0;
        for (int i = 1; i <= jsonObject.length(); i++) {
            String fBase = base + i;
            sum += Integer.parseInt(jsonObject.get(fBase).toString());
        }
        return sum;
    }

    /**
     * 汇总数据公共方法--求平均
     */
    public double huiZongLuoTongAverage(String json, String base) throws Exception {
        JSONObject jsonObject = new JSONObject(json);
        double sum = 0.0;
        for (int i = 1; i <= jsonObject.length(); i++) {
            String fBase = base + i;
            sum += Double.parseDouble(jsonObject.get(fBase).toString());
        }
        return sum / jsonObject.length();
    }

    /**
     * 汇总数据公共方法
     */
    //public LuoTongHuiZong huiZongLuoTong(SperoTable speroTable) throws Exception {
    //    LuoTongHuiZong luoTongHuiZong = new LuoTongHuiZong();
    //    SumLuoTong cx = this.huiZongLuoTongSum(speroTable.getCx(), "cx");
    //    SumLuoTong mj = this.huiZongLuoTongSum(speroTable.getMj(), "mj");
    //    SumLuoTong dc = this.huiZongLuoTongSum(speroTable.getDc(), "dc");
    //    SumLuoTong nj = this.huiZongLuoTongSum(speroTable.getNj(), "nj");
    //    SumLuoTong xh = this.huiZongLuoTongSum(speroTable.getXh(), "xh");
    //    SumLuoTong qc = this.huiZongLuoTongSum(speroTable.getQc(), "qc");
    //    SumLuoTong yj = this.huiZongLuoTongSum(speroTable.getYj(), "yj");
    //    SumLuoTong hg = this.huiZongLuoTongSum(speroTable.getHg(), "hg");
    //    SumLuoTong cz = this.huiZongLuoTongSum(speroTable.getCz(), "cz");
    //    SumLuoTong xtq = this.huiZongLuoTongSum(speroTable.getXq(), "xq");
    //    SumLuoTong yx = this.huiZongLuoTongSum(speroTable.getYx(), "yx");
    //    SumLuoTong mt = this.huiZongLuoTongSum(speroTable.getMt(), "mt");
    //    SumLuoTong cc = this.huiZongLuoTongSum(speroTable.getCc(), "cc");
    //    SumLuoTong bc = this.huiZongLuoTongSum(speroTable.getBc(), "bc");
    //    double xl = this.huiZongLuoTongAverage(speroTable.getXl(), "xl");
    //    luoTongHuiZong.setCx(cx);
    //    luoTongHuiZong.setMj(mj);
    //    luoTongHuiZong.setDc(dc);
    //    luoTongHuiZong.setNj(nj);
    //    luoTongHuiZong.setXh(xh);
    //    luoTongHuiZong.setQc(qc);
    //    luoTongHuiZong.setYj(yj);
    //    luoTongHuiZong.setHg(hg);
    //    luoTongHuiZong.setCz(cz);
    //    luoTongHuiZong.setXtq(xtq);
    //    luoTongHuiZong.setYx(yx);
    //    luoTongHuiZong.setMt(mt);
    //    luoTongHuiZong.setCc(cc);
    //    luoTongHuiZong.setBc(bc);
    //    luoTongHuiZong.setXl(xl);
    //    return luoTongHuiZong;
    //}

    /**
     * 获取两个时间点之间, 按照整点每隔半小时的字符串类型的时间点
     *
     * @param beginTime
     * @param endTime
     * @return
     */
    public List<String> getPointInTimes(LocalDateTime beginTime, LocalDateTime endTime) {
        return this.getPointInTimesByFormat(beginTime, endTime, "yyyyMMddHHmm");
    }

    public List<String> getDaysBySection(LocalDateTime beginTime, LocalDateTime endTime){
        return this.getDaysBySectionAndFormat(beginTime, endTime, "yyyyMMdd");
    }

    public List<String> getDaysBySectionAndFormat(LocalDateTime beginTime, LocalDateTime endTime, String format){
        List<String> daysBySection = new ArrayList<>();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
        while(beginTime.compareTo(endTime) != 1){
            String beginTimeStr = formatter.format(beginTime);
            daysBySection.add(beginTimeStr);
            beginTime = beginTime.plusDays(1);
        }
        return daysBySection;
    }

    /**
     * 获取两个时间点之间, 按照整点每隔半小时的字符串类型的时间点
     *
     * @param beginTime
     * @param endTime
     * @return
     */
    public List<String> getPointInTimesByFormat(LocalDateTime beginTime, LocalDateTime endTime, String format) {
        // 获取开始时间的分钟, 如果大于30分, 则时+1,分归0; 如果小于30分, 则分设置成30;
        Integer beginMinute = beginTime.getMinute();
        if (beginMinute < 30 && beginMinute != 0) {
            beginTime = beginTime.plusMinutes(30 - beginMinute);
        } else if (beginMinute > 30) {
            beginTime = beginTime.plusHours(1);
            beginTime = beginTime.minusMinutes(beginMinute);
        }
        // 获取结束时间的分钟, 如果大于30分, 则按照30分; 如果小于30分, 则按照整点
        Integer endMinute = endTime.getMinute();
        if (endMinute > 30) {
            endTime = endTime.minusMinutes(endMinute - 30);
        } else if (endMinute < 30) {
            endTime = endTime.minusMinutes(endMinute);
        }
        // 定义日期格式化格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(format);
        List<String> pointInTimes = new ArrayList<>();
        while (beginTime.compareTo(endTime) != 1) {
            pointInTimes.add(formatter.format(beginTime));
            beginTime = beginTime.plusMinutes(30);
            System.out.println(beginTime.compareTo(endTime));
        }
        return pointInTimes;
    }

    /**
     * 获取今日0点至现在所有的整点时间字符串
     * @return
     */
    public List<String> getHoursNowByToday() {
        LocalDateTime now = LocalDateTime.now();
        List<String> hoursList = new ArrayList<>();
        LocalDateTime zeroDate = LocalDateTime.of(LocalDateTime.now().toLocalDate(), LocalTime.MIN);
        // 定义日期格式化格式
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHH");
        // 获取现在的小时
        Integer hour = now.getHour();
        while(zeroDate.getHour() <= hour){
            String zeroDateString = formatter.format(zeroDate);
            hoursList.add(zeroDateString);
            zeroDate = zeroDate.plusHours(1);
        }
        return hoursList;
    }

    /**
     * 字符串日期类型转换
     * @param oldDate 被转换的日期字符串
     * @param oldFormat 被转换的日期字符串格式
     * @param format 要转换成的日期字符串格式
     * @return
     */
    public String dateTimeFormat(String oldDate, String oldFormat, String format){
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(format);
        LocalDateTime formatLocalDate = LocalDateTime.parse(oldDate, DateTimeFormatter.ofPattern(oldFormat));
        return dateTimeFormatter.format(formatLocalDate);
    }

}
